//Sun Jun 12 17:30:46 CDT 2011
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

class TeamBuilder {
public:
	vector <int> specialLocations(vector <string>);
};

vector <int> TeamBuilder::specialLocations(vector <string> paths) {
	int N = paths.size();
	vector<vector<int> > v(N, vector<int>(N, 0));
	
	for(int i=0; i<N; i++){
		for(int j=0; j<N; j++){
			v[i][j] = paths[i][j]-'0';
		}
	}
	
	for(int k=0; k<N; k++){
		for(int i=0; i<N; i++){
			for(int j=0; j<N; j++){
				if(v[i][k]&&v[k][j])
					v[i][j] = 1;
			}
		}
	}
	vector<int> ret(2,0);
	for(int i=0; i<N; i++){
		int c1 = 0;
		int c2 = 0;
		for(int j=0; j<N; j++){
			if(i==j) continue;
			c1 += v[i][j];
			c2 += v[j][i];
		}
		ret[0] += ((c1==N-1) ? 1:0);
		ret[1] += ((c2==N-1) ? 1:0);
	}
	return ret;
}

//<%:testing-code%>
//Powered by [KawigiEdit] 2.0!
